<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>day09_demo01</title>
<script>
	//采用直接量的方式创建对象
	function f1() {
		var stu = {
			"name":"zhangsan",
			"age":23,
			"work":function(){
				alert("我爱学习java");
			}
		};
		alert(stu.name);
		alert(stu.age);
		stu.work();
	}
	
	//采用内置构造器创造对象
	function f2(){
		var tch=new Object();
		tch.name="cang";
		tch.age=20;
		tch.sal=5000;
		tch.work=function(){
			alert("我教java!");
		};
		alert(tch.name);
		alert(tch.age);
		alert(tch.sal);
		tch.work();	
	
	}
	
	//采用自定义构造器创造对象
	function Coder(name,age,work){
		this.name=name;
		this.age=age;
		//this指代当前对象
		//this.job给当前对象加job属性
		//=work是将参数work赋值给此属性
		this.job=work;
	}
	function f3(){
		var coder=new Coder(
			"wangwu",
			24,
			function(){
				alert("I am happy!我写java");				
			}
		);
		alert(coder.name);
		alert(coder.age);
		coder.job;	
		
	}	
	
	
	
	
	
	
</script>



</head>
<body>
	<input type="button" value="按钮1" onclick="f1();" />
	<input type="button" value="按钮2" onclick="f2();" />
	<input type="button" value="按钮3" onclick="f3();" />



</body>
</html>